<?php

namespace App\Http\Controllers\Client\Member;

use App\Models\Ass;
use App\Models\AssMember;
use App\Models\Member\Member;
use App\Services\Com\UtilService;
use Illuminate\Http\Request;
use App\Http\Controllers\RootController as Controller;
use Illuminate\Support\Facades\DB;

class AssDelController extends Controller
{
    public function handle(Request $request, Member $model)
    {
        /******参数 start******/
        $param['ass_id'] = (int)$request->input('ass_id', '');

        $rules    = [
            'ass_id'  => 'required',
        ];
        $messages = [
            'ass_id.required'                    => '请传入上报记录id',
        ];

        if (true !== ($error = $this->validator($param, $rules, $messages)))
        {
            return $this->failure($error, 'VALIDATION_FAIL');
        }

        try
        {
            DB::beginTransaction();

            Ass::destroy($param['ass_id']);

            AssMember::where('ass_id', $param['ass_id'])->delete();

            DB::commit();
        }
        catch (\Exception $e)
        {
            DB::rollBack();
            return $this->failure($e->getMessage(), 'E_DB');
        }

        return $this->success();
    }
}
